package com.zxl.grocery.microservice.auth.server.feign;

import com.zxl.grocery.microservice.api.user.UserInfo;
import com.zxl.grocery.microservice.auth.server.configuration.FeignConfiguration;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * 服务与服务之间的调用
 * Created by zxl on 2017/10/13 0013.
 */
@FeignClient(value = "grocery-admin",configuration = FeignConfiguration.class)
public interface IUserService {
  //Feign的坑
  //1、FeignClient接口，不能使用@GettingMapping 之类的组合注解
  //2、FeignClient接口中，如果使用到@PathVariable ，必须指定其value。这边的@PathVariable("username") 中的”username”，不能省略，必须指定。
  //3、FeignClient多参数的构造，只要参数是复杂对象，即使指定了是GET方法，feign依然会以POST方法进行发送请求。例如：如果想要请求grocery-admin服务，并且参数有多个例如：http://grocery-admin/query-by?id=1&username=张三 要怎么办呢？如果直接使用复杂对象：public User queryBy(User user)会报错;正确的写法有两种：1、public User queryBy(@RequestParam("id")Long id, @RequestParam("username")String username);2、public List<User> queryBy(@RequestParam Map<String, Object> param);
//  @RequestMapping(value = "/api/user/username/{username}", method = RequestMethod.GET)
//  public UserInfo getUserByUsername(@PathVariable("username") String username);

  //获取用户权限
//  @RequestMapping(value = "/api/user/un/{username}/permissions", method = RequestMethod.GET)
//  public List<PermissionInfo> getPermissionByUsername(@PathVariable("username") String username);
//
//  @RequestMapping(value = "/api/permissions", method = RequestMethod.GET)
//  List<PermissionInfo> getAllPermissionInfo();

  @RequestMapping(value = "/api/user/validate", method = RequestMethod.POST)
  public UserInfo validate(@RequestParam("username") String username, @RequestParam("password") String password);
}
